package java8stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by ZhuQianli on 2018/1/16.
 */
public class StreamFilterMapCollect {
    public static void main(String[] args) {

        List list = new ArrayList();
        for (int i = 0; i < 100; i++) {
            list.add(i);
        }

        Stream stream = list.stream().filter(StreamFilterMapCollect::filter).map(StreamFilterMapCollect::print);

        List collect = (List) stream.collect(Collectors.toList());

        System.out.println(collect);


    }

    private static boolean filter(Object object) {
        if (object instanceof Integer) {
            Integer integer = (Integer) object;
            return integer % 2 == 0;
        }
        return false;
    }

    private static Object print(Object object) {
        if (object instanceof Integer) {
            Integer integer = (Integer) object;
            System.out.println(integer);
            return --integer;
        }
        return object;
    }
}
